package com.yuanfeng.action.front.pay;

import com.opensymphony.xwork2.ActionSupport;
import com.yuanfeng.util.PaymentUtil;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;

/**
 * 支付结果页面
 * Created by yuanfeng on 2019/5/8 8:40
 */
public class ResultAction extends ActionSupport {

    public String payResult(){

        HttpServletRequest request = ServletActionContext.getRequest();
        //对hamc进行解密，且验证是否是与发出的支付请求信息一致！！！！
        String hmac  = request.getParameter("hmac");
        String p1_MerId  = request.getParameter("p1_MerId");
        String r0_Cmd  = request.getParameter("r0_Cmd");
        String r1_Code  = request.getParameter("r1_Code");
        String r2_TrxId  = request.getParameter("r2_TrxId");
        String r3_Amt  = request.getParameter("r3_Amt");
        String r4_Cur  = request.getParameter("r4_Cur");
        String r5_Pid  = request.getParameter("r5_Pid");
        String r6_Order  = request.getParameter("r6_Order");
        String r7_Uid  = request.getParameter("r7_Uid");
        String r8_MP  = request.getParameter("r8_MP");
        String r9_BType  = request.getParameter("r9_BType");

        boolean result = PaymentUtil.verifyCallback(
                hmac,
                p1_MerId,
                r0_Cmd,
                r1_Code,
                r2_TrxId,
                r3_Amt,
                r4_Cur,
                r5_Pid,
                r6_Order,
                r7_Uid,
                r8_MP,
                r9_BType,
                "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl");

        if(result){
            //支付成功
            return SUCCESS;
        }else{
            return "failed";
        }
    }
}
